Repository navigation
fix(durable): dispatch effects from Start, Tick and RunService - #235
Merged
Merged
Conversation
5 tasks done
reka18
force-pushed
the
fix/durable-effect-dispatch
branch
from
November 5, 2026 16:38
ebb5863 to
ef9c0a8
Compare
reka18
force-pushed
the
fix/durable-effect-dispatch
branch
from
November 5, 2026 16:40
ef9c0a8 to
d46adf2
Compare
reka18
force-pushed
the
fix/durable-effect-dispatch
branch
from
November 5, 2026 16:53
d46adf2 to
cc4d8cc
Compare
reka18
force-pushed
the
fix/durable-effect-dispatch
branch
from
November 5, 2026 17:09
cc4d8cc to
d657891
Compare
reka18
force-pushed
the
fix/durable-effect-dispatch
branch
from
November 5, 2026 17:14
d657891 to
3e41947
Compare
reka18
force-pushed
the
fix/durable-effect-dispatch
branch
from
November 5, 2026 17:22
3e41947 to
3edd2ee
Compare
reka18
force-pushed
the
fix/durable-effect-dispatch
branch
from
November 5, 2026 17:33
3edd2ee to
aae543d
Compare
reka18
force-pushed
the
fix/durable-effect-dispatch
branch
from
November 5, 2026 17:42
aae543d to
50bbc98
Compare
reka18
force-pushed
the
fix/durable-effect-dispatch
branch
from
November 5, 2026 18:04
50bbc98 to
a14c4ed
Compare
reka18
force-pushed
the
fix/durable-effect-dispatch
branch
from
November 5, 2026 18:20
a14c4ed to
90bcbfb
Compare
This was referenced Nov 10, 2026
Open
This was referenced Nov 17, 2026
Only Fire dispatched domain effects. Tick and RunService now record a step through the same helper as Fire, then dispatch its effects as Fire does, after the append and before any checkpoint. A failed dispatch fails the Handle before its checkpoint, so a later checkpoint can't compact the effect away, and Recover retries it. Start applies the initial entry's effects before the baseline, so a handler failure leaves no instance; they're at-least-once. DeliverToActor records through the same helpers, and persistStep is gone. - EffectInstance gives a handler its instance id, because effect ids repeat across instances. - state.ServiceRunner gains WithResultTransform, so a service's result reaches the machine in the JSON-decoded form a replay supplies, and an error message-only. A transform that returns no error for an unbound service doesn't turn it into a success. A result whose JSON form won't decode fails RunService and records nothing. - One helper calls the effect handler for Start, a step and Recover, and turns a handler panic into ErrEffectDispatch; the shared dispatch path does the same for a DispatchStore whose Dispatched or MarkDispatched panics or fails. A service error whose Error method panics settles with a message saying so, its invalid UTF-8 replaced. - A KindedEffect that won't marshal, or whose MarshalJSON panics, is recorded by id and kind, with the reason in Meta under crucible.marshalError, on every path including Fire, and dispatches as any effect does. - Recover re-sends a tick's and a service settle's effects. journalFormat is 2, and Recover sends them only for a Record of format 2 or later, so it doesn't send an older version's, which never dispatched them. - An effect handler wired with a Store that isn't a DispatchStore is refused by Start, Recover and the stateless Runner.Fire, and by dispatch itself, with the new ErrNoDispatchStore, a permanent error that doesn't match ErrEffectDispatch. It used to skip every effect silently. - Tick hands each fired timer transition's effects to the service runner and then the actor system, under the step's context, live and on replay for a tick of format 2 or later, so a timer that leaves a state stops its service and actor, and one that enters a state starts and spawns them. This covers #236's Tick items and unskips its two tests. - A settle leaves its follow-on services to the ServiceRunner, which already armed them, as replay does, and a checkpoint written without a service registry keeps the settled services. Effects from a parent transition an actor drives are still not dispatched (#257). Relates to #214. Signed-off-by: Ray Karnes <ray.karnes@stablekernel.com>
Tick checked ctx before handing the fired timers' effects to the service runner and the actor system, then only looked for a parent Fire a context refused. A ctx that ended while the tick spawned its actors could cost a message one actor sent another, which no Fire reports, so the tick was journaled and Recover delivered that message under a live context, which live never applied. Tick now rechecks ctx after the absorb, as RunService does after its settle: it fails the Handle and records nothing, and a recovered Handle re-arms the timer. Tests, each committed either way: - Tick: a context that ends while the tick spawns actors records nothing. - Fire, Tick and RunService dispatch a recorded step's effects under the caller's context alike: a handler that ignores an ended context applies the effect and the step succeeds; one that honors it fails the Handle with ErrEffectDispatch, and Recover sends the effect once. - RunService: a result whose JSON form won't decode, or that has no JSON form, settles onDone before the step fails. Its Assign runs on the stand-in, and the state it enters spawns its actor, then RunService returns ErrHandleFailed and records nothing. A reducer that panics on the stand-in refuses the Fire, and RunService still returns ErrHandleFailed. This pins today's behavior for a design decision. Signed-off-by: Ray Karnes <ray.karnes@stablekernel.com>
Fire looked only for a parent Fire a context refused after handing the event's effects to the actor system. A ctx that ended while the Fire spawned its actors could cost a message one actor sent another, which no Fire reports, so the Fire was journaled and Recover delivered that message under a live context, which live never applied. A Fire that spawned an actor now rechecks ctx after the absorb, as Tick and RunService do: it fails the Handle and records nothing, and the event fires again on a recovered Handle. A Fire that spawned no actor still records when its context ends once the kernel applied the event. DeliverToActor already rechecks ctx after the delivery. Start and Recover keep their documented rule: a context that ends once their actors spawned, with no parent Fire refused, doesn't fail them. Document what RunService does with a result whose JSON form won't decode, or that has no JSON form: the onDone Assign runs once on a stand-in and the onDone state starts its actors and services before RunService returns ErrHandleFailed and records nothing. Keep results JSON round-trippable, and have an onDone Assign check the payload's type. A stacked change, #258, refuses such a result before any Assign runs. Tests: - Fire: a context that ends while the Fire spawns actors records nothing, and the event fires again on the recovered Handle. - Fire: without an actor palette, a context that ends once the kernel applied the event still records. Signed-off-by: Ray Karnes <ray.karnes@stablekernel.com>
Fire rechecked an ended ctx after its absorb only when it spawned an actor, and Tick whenever a timer fired. Neither matched what an ended ctx can cost. A Fire that sent a running actor a message (SendTo, ForwardTo) recorded though the actor refused the message under the ended ctx, so the message was lost for good: the caller saw success, and a recovered Handle starts the actor fresh. A Tick on a machine with timers and services but no actor palette failed its Handle when ctx ended during the absorb, where the same Fire records, though handing services to the runner runs nothing ctx can refuse. Fire and Tick now share one rule: recheck ctx after the absorb when the step handed a wired actor system a spawn or a message to an actor. Stopping an actor, a response with no sender, and timers and services don't count, so a Fire that touched no actor still records when ctx ends after the apply. Tick still fails when ctx ends while its timers fire. RunService keeps rechecking ctx whatever its absorb did: the service itself ran under ctx, so its outcome can be one ctx's ending caused. The RunService doc no longer names a pending change. Tests, each committed either way: - Fire (by SendTo and by ForwardTo) and Tick: a ctx that ends while the step messages a running actor records nothing, and the message is delivered when the step runs again on a recovered Handle. - Fire and Tick: with timers and a service but no actor palette, a ctx that ends after the kernel applied the step records, and the service is in flight live and recovered. - Fire: a ctx that ends while the step stops an actor and responds to no sender records. - Recover: an older version's journal, of format 0 or 1, whose tick left a state with its service in flight, recovers with the service in flight; a checkpoint then drops it, a settle follows, and every later Recover fails with "no in-flight service to settle". This pins today's behavior for a decision. Signed-off-by: Ray Karnes <ray.karnes@stablekernel.com>
…il only on refused parent Fires A parent's forwardTo forwarded nothing: Fire and Tick handed the actor system their effects without the event. Fire now absorbs through AbsorbFor with its event, and Tick with each timer's event, rebuilt from the trace with the Runner's event codec. Actor deliveries aren't replayed, so Recover starts the actor fresh, as for a SendTo. This was already so on main for Fire. A step could spawn an actor for a state a parent Fire its absorb drove had already left, as when one region's actor exits another region's state, by one Fire or by timers that fire in one Tick. The live Handle ran an orphan Recover never spawns. The step now feeds the actor system one effect at a time and skips a state's spawn whose actor a parent Fire since stopped. Fire and Tick no longer fail the Handle because their context ended after they handed actors work; only a parent Fire a context refused fails them, as for Start and Recover. A message an actor refuses under the ended context is lost, as actor deliveries are across Recover, and failing the step would have the retry run actor behaviors again. Signed-off-by: Ray Karnes <ray.karnes@stablekernel.com>
…mers; decode a timer's event only to forward it c393fd3 skipped a step's spawn for a state a parent Fire had left, but only in Fire and Tick. Start and Recover still spawned the configuration's actors in one batch, so when one region's actor sent the parent a message as it started that left another region's state, that state's actor spawned after, and ran where a Recover from the journal never spawns it. Start and Recover's new actors now go through the same per-effect absorb. Recover respawns the actors that were running in one batch, so when one's respawn fails with an onError that leaves another of their states, it now stops each respawned actor whose state isn't active. Within a Tick, a timer that entered a state spawned its actor even when a later timer of the same tick left it, so the actor's behavior ran before the later timer stopped it. A step now skips a state's spawn that a later effect of the step stops, the later timers' included. Checking the declaring state against the configuration instead wasn't enough on its own: state exposes active leaves only, and a state left and entered again in one step is active at the end, so its first spawn would still run. Tick decoded every fired timer's event through the event codec and dropped a decode error. It now decodes only for a forwardTo an actor system can carry. On a decode error it forwards nothing, records the tick, dispatches its effects, and returns the codec's error with the results; the Handle carries on, as when an actor can't take a message. A step with no event to forward no longer hands the actor system a ForwardEvent, which it delivered as a nil event. Signed-off-by: Ray Karnes <ray.karnes@stablekernel.com>
…nil event Signed-off-by: Ray Karnes <ray.karnes@stablekernel.com>
This was referenced Nov 17, 2026
joshua-temple
previously approved these changes
Nov 17, 2026
joshua-temple
left a comment
Collaborator
There was a problem hiding this comment.
- Accepted behavior change:
ErrNoDispatchStore. StatelessRunner.Fireon a custom Store now errors instead of silently skipping effects. - Please add a changelog note for it.
- Follow-ups filed: #263, #264
- Non-blocking suggestions
- Export a sentinel for the non-fatal
Tickerror (runner.go ~1133) - Route
recordEffectsmarshal failures to the observer (effect.go ~119) - Restore
rec.Stepin the panic message (effect.go ~239) - Run full
mage checkbefore merge
- Export a sentinel for the non-fatal
This was referenced Nov 17, 2026
Contributor
Author
|
Punting two of the non-blocking suggestions, since both add public API:
The changelog note, |
A panic in the Store's Dispatched or MarkDispatched now reports the step it dispatched for, as it did before. The changelog now says a stateless Runner.Fire on a Store without dispatch tracking returns ErrNoDispatchStore. Signed-off-by: Ray Karnes <ray.karnes@stablekernel.com>
Contributor
Author
|
Done in 2176d0e:
|
joshua-temple
approved these changes
Nov 17, 2026
2 tasks done
Contributor
Author
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this change does
Domain effects now reach the handler from
Start,TickandRunService, not onlyFire, and a timer transition now starts and stops services and actors.TickandRunServicerecord their step the wayFiredoes: append under the step lock, then dispatch the effects outside it, before any checkpoint.Recoverretries the effect, and fails withErrEffectDispatchwhile the handler still does. A handler panic, or a panic or error in the Store's dispatch tracking, returnsErrEffectDispatchtoo, fromStart, a step andRecover. This changes behavior: aFireafter a failed dispatch used to be accepted.Startencodes the baseline, applies the initial entry's effects, then writes the baseline, and applies none if the entry failed. Those effects are at-least-once: a handler failure, a failed baseline write or overlappingStartcalls re-apply them. Tests pin this contract.Recoverre-sends a Record's unmarked effects only for this version's Records (journal format 2), and for everyFireRecord, so an older journal's uncompactedTickand service steps don't send effects they never sent.KindedEffectwhose payload can't marshal, or whoseMarshalJSONpanics, no longer fails a step: it's recorded by id and kind, with the error underMeta["crucible.marshalError"], andRecoverre-derives its value for dispatch. This relaxesFire, which failed in this case on main.durable.EffectInstance(ctx)gives a handler the instance, because effect ids repeat across instances (durable: defects found in the platform-redesign review #214 question 5). This takes the issue's second option, so the dispatched set needs no migration.state.ServiceRunner.WithResultTransform, an additive change to the frozenstatemodule.durableuses it so a service result reachesAssignin its JSON-decoded form live as well as on replay, so a retried effect can't differ from the first attempt under the same id. A result that encodes but won't decode fails the step and records nothing; a service error stays message-only, soerrors.Isanderrors.Asdon't match in onError.FireandRunServicealready did. Without it, a timer that left a service's state left the service in flight, and a checkpoint followed by a settle made everyRecoverfail with "no in-flight service to settle". Timer-driven work runs under the step's context, and a multi-timerTickstarts every timer's services before its actors. This covers fix(durable): keep timers across recovery and skip idle ticks #236's Tick items and unskips main's two "fix(durable): keep timers across recovery and skip idle ticks #236 fixes it" tests.StartandRecover's rule: only a parent Fire that an ended context refused fails the step. A message an actor refuses because the step's context ended is lost, as actor deliveries are acrossRecover.forwardToonFireor a timer transition forwards the step's event instead of nil (on main,Fireforwarded nil).Fire,Tick,StartandRecover, so the live Handle matches whatRecoverrebuilds.Please check these:
WithEffectHandleron a Store that isn't aDispatchStoreis now refused with the new exportedErrNoDispatchStore, instead of silently applying no effects.NewRunnercan't return an error, soStart,Recoverand the statelessFirerefuse before any Store read, write or handler call. It's a permanent configuration error, so it doesn't matchErrEffectDispatch, which callers retry.MemStoreandFileStoreboth implementDispatchStore. I'd suggest refusing, but it's your call: the alternatives are dispatching at-least-once with no dedupe on such Stores, or keeping the documented silent skip.AssignJSON-decoded on the live run too. Before, live got the ServiceFn's Go value and replay got generic JSON. Now both get the generic form (a struct asmap[string]any, a number asfloat64), so live and replay agree. An existing reducer that type-asserts the concrete result stops matching on the live run without an error. The fooddelivery example needed afloat64case. Typed results throughWithEventDataDecoderare in the stacked follow-up, not here.Recoverfails while the handler is down. A handler that always refuses an effect wedges the instance. This needs a ruling.journalFormatis now 2, which gates the re-send rule above. Main's format check is unchanged.Out of scope, tracked separately:
Recover: durable: an upgraded instance whose older tick left a service in flight can fail every Recover #259 (pinned).forwardToon an actor-driven parent Fire still forwards nil: state: forwardTo on an actor-driven parent Fire or a service settle forwards nil #260.stopActorduring a step or a respawn can leave the actor sets out of step: durable: an explicit stopActor during a step or a respawn can leave the actor sets out of step #261.Why
Effects from entry, timer and service transitions never reached the handler, and a failed effect could be compacted away and never retried.
Relates to: #214
Evidence
On
GOTOOLCHAIN=go1.27.4, with-race:go test ./...in every modulegolangci-lintv2.15.0 indurableandstateEach key guarantee was mutation-checked: reverting Tick's dispatch,
Recover's re-send, the old-version gate, the Store refusal, the Tick driver absorb (live and replay) or the panic guards makes a test fail.Checklist
git commit -s) per the DCOtype: subject)mage checkpasses locally (lint + race tests + govulncheck)